Completed
Push — master ( edfbd4...6aa1a8 )
by
unknown
02:12
created

request.js ➔ describe(ꞌRequestꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 147

Duplication

Lines 0
Ratio 0 %

Importance

Changes 12
Bugs 3 Features 2
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 147
rs 8.2857
c 12
b 3
f 2

18 Functions

Rating   Name   Duplication   Size   Complexity  
A request.js ➔ ... ➔ it(ꞌSql.executeQuery()ꞌ) 0 12 2
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() >=ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() >ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() !=ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() ANDꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() <=ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() LIKEꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeFromClause()ꞌ) 0 4 1
A request.js ➔ ... ➔ it(ꞌSql.requestList()ꞌ) 0 16 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() NOT INꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() NOT LIKEꞌ) 0 5 1
A request.js ➔ ... ➔ before 0 11 1
A request.js ➔ ... ➔ it(ꞌSql.getSourceType()ꞌ) 0 7 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() INꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() ORꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() =ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌSql.executeWhereClause() <ꞌ) 0 5 1
A request.js ➔ ... ➔ it(ꞌUtil.getAllAttributes()ꞌ) 0 5 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var chai = require('chai');
2
var path = require('path');
3
4
var config = require('../src/cli').config
5
config.set({root: __dirname + '/fixtures'})
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
6
7
var Sql = require('../src/cli').Sql
8
var Util = require('../src/cli').Util
9
var fileAttr = require('../src/cli').fileAttr
10
var Manager = require('../src/cli').Manager;
11
var fse = require('fs-extra');
12
13
describe('Request', function() {
14
  before( function(done) {
15
    Manager.instance.init()
16
      .then(function () {
17
        this.fixture = {
18
          tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
19
          json: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
20
        }
21
        done()
22
        
23
      }.bind(this))
24
  });
25
26
  /**
27
   * Sql.getAllAttributes
28
   * 
29
   */
30
  it('Util.getAllAttributes()', function(done) {
31
    var attributes = Util.getAllAttributes(this.fixture.tag, this.fixture.json)
32
    chai.expect(attributes.sourceString).to.contain('select');
33
    done();
34
  });
35
36
  /**
37
   * Sql.executeQuery
38
   * 
39
   */
40
  it('Sql.executeQuery()', function(done) {
41
    try {
42
      var match = 'select * from ../'
43
      var jsonPage = {}
0 ignored issues
show
Unused Code introduced by
The variable jsonPage seems to be never used. Consider removing it.
Loading history...
44
      var res = Sql.handleSqlRequest(match, {})
45
46
      chai.assert.equal(res.string, 'select ["*"] from ["___abe_dot______abe_dot______abe___"] ', 'select not well formatted')
47
      done();
48
    } catch (x) {
49
      done(x);
50
    }
51
  });
52
53
  /**
54
   * Sql.executeFromClause
55
   * 
56
   */
57
  it('Sql.executeFromClause()', function() {
58
    var res = Sql.executeFromClause(['/'], ['/'])
59
    chai.expect(res).to.have.length(2);
60
  });
61
62
  /**
63
   * Sql.whereEquals
64
   * 
65
   */
66
  it('Sql.executeWhereClause() >', function() {
67
    var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`>`1`', {})
68
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
69
    chai.expect(res).to.have.length(1);
70
  });
71
  it('Sql.executeWhereClause() >=', function() {
72
    var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`>=`1`', {})
73
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
74
    chai.expect(res).to.have.length(2);
75
  });
76
  it('Sql.executeWhereClause() <', function() {
77
    var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`<`1`', {})
78
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
79
    chai.expect(res).to.have.length(0);
80
  });
81
  it('Sql.executeWhereClause() <=', function() {
82
    var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`<=`1`', {})
83
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
84
    chai.expect(res).to.have.length(1);
85
  });
86
  it('Sql.executeWhereClause() =', function() {
87
    var request = Sql.handleSqlRequest('select title from ./ where template=`article`', {})
88
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
89
    chai.expect(res).to.have.length(1);
90
  });
91
  it('Sql.executeWhereClause() !=', function() {
92
    var request = Sql.handleSqlRequest('select title from ./ where template!=`homepage`', {})
93
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
94
    chai.expect(res).to.have.length(1);
95
  });
96
  it('Sql.executeWhereClause() LIKE', function() {
97
    var request = Sql.handleSqlRequest('select title from ./ where template LIKE `home`', {})
98
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
99
    chai.expect(res).to.have.length(1);
100
  });
101
  it('Sql.executeWhereClause() NOT LIKE', function() {
102
    var request = Sql.handleSqlRequest('select title from ./ where template NOT LIKE `home`', {})
103
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
104
    chai.expect(res).to.have.length(1);
105
  });
106
  it('Sql.executeWhereClause() AND', function() {
107
    var request = Sql.handleSqlRequest('select title from ./ where template=`homepage` AND title=`homepage`', {})
108
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
109
    chai.expect(res).to.have.length(1);
110
  });
111
  it('Sql.executeWhereClause() OR', function() {
112
    var request = Sql.handleSqlRequest('select title from ./ where template=`homepage` OR template=`article`', {})
113
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
114
    chai.expect(res).to.have.length(2);
115
  });
116
  it('Sql.executeWhereClause() IN', function() {
117
    var request = Sql.handleSqlRequest('select title from ./ where template IN (`homepage`,`test`) AND title=`homepage`', {})
118
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
119
    chai.expect(res).to.have.length(1);
120
  });
121
  it('Sql.executeWhereClause() NOT IN', function() {
122
    var request = Sql.handleSqlRequest('select title from ./ where template NOT IN (`homepage`,`test`)', {})
123
    var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {})
124
    chai.expect(res).to.have.length(1);
125
  });
126
127
  /**
128
   * Sql.whereLike
129
   * 
130
   */
131
  it('Sql.getSourceType()', function() {
132
    chai.expect(Sql.getSourceType('http://google.com')).to.equal('url');
133
    chai.expect(Sql.getSourceType('select * from test')).to.equal('request');
134
    chai.expect(Sql.getSourceType('{"test":"test"}')).to.equal('value');
135
    chai.expect(Sql.getSourceType('references.json')).to.equal('file');
136
    chai.expect(Sql.getSourceType('test')).to.equal('other');
137
  });
138
139
  /**
140
   * Sql.requestList
141
   * 
142
   */
143
  it('Sql.requestList()', function(done) {
144
    let util = new Util()
145
    var matches = util.dataRequest(this.fixture.tag)
146
147
    chai.expect(matches[0][0]).to.not.be.null
0 ignored issues
show
introduced by
The result of the property access to chai.expect(matches.0.0).to.not.be.null is not used.
Loading history...
148
149
    var attributes = Util.getAllAttributes(matches[0][0], {})
150
    chai.expect(matches[0][0]).to.not.be.null
0 ignored issues
show
introduced by
The result of the property access to chai.expect(matches.0.0).to.not.be.null is not used.
Loading history...
151
152
    var jsonPage = {}
153
    Util.requestList(attributes, '', matches[0][0], jsonPage)
154
      .then(function () {
155
        chai.expect(jsonPage.abe_source).to.not.be.undefined
0 ignored issues
show
introduced by
The result of the property access to chai.expect(jsonPage.abe...ce).to.not.be.undefined is not used.
Loading history...
156
        done()
157
      })
158
  });
159
});
160